package PenTest.eleme.ACM0412;

import java.util.Scanner;

public class ACM2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.nextLine();
        int n = Integer.parseInt(s1.split(" ")[0]);
        int q = Integer.parseInt(s1.split(" ")[1]);
        //sc.nextLine();
        String[] sArray = sc.nextLine().split(" ");
        ACM2 acm2 = new ACM2();
        int[] arr = acm2.stringToInt(sArray);
        //sc.nextLine();
        int[] ansArr = new int[q];
        for (int i = 0; i < q; i++) {
            int[] currArr=acm2.stringToInt(sc.nextLine().split(" "));
            int l = currArr[0];
            int r = currArr[1];
            int k = currArr[2];
            int val = arr[l - 1];
            int s = l-1;
            while (l<=r) {
                if (val == k) {
                    ansArr[i]=s+1;
                    break;
                }
                s++;
                l++;
                if (s <= arr.length - 1) {
                    val = val | arr[s];
                }
            }
            if (l > r) {
                ansArr[i]=-1;
            }
        }
        for (int i = 0; i < q; i++) {
            System.out.println(ansArr[i]);
        }
    }

    public int[] stringToInt(String[] arr){
        int[] array = new int[arr.length];
        for (int i = 0; i < arr.length; i++) {
            array[i] = Integer.parseInt(arr[i]);
        }
        return array;
    }

}
